package com.example.cron.service.impl;

import com.example.common.enums.SystemStatus;
import com.example.cron.jpa.RxMainRepository;
import com.example.cron.service.RecipeTask;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Date;

/**
 * @ClassName RecipeTaskImpl
 * @Author wengjt
 * @Date 2021/3/2311:59
 * @Description
 **/
@Component
public class RecipeTaskImpl implements RecipeTask {

    @Resource
    private RxMainRepository rxMainRepository;
    /*
     * @Author wengjt
     * @Description  关闭超时的处方//TODO
     * @Date 11:59 2021/3/23
     * @Param
     * @return 
     **/
    @Override
    public void cancelTimeOutRecipe() {
        rxMainRepository.findBySystemStatus(SystemStatus.UN_PAY.getName()).stream().filter(rxMain -> {
            //删选出超时的处方
            long now =new Date().getTime();
            long end= (rxMain.getCreateTime().getTime()+3*24*3600*1000)/86400*1000;
            return now>end;
        }).forEach(rxMain -> {
            rxMain.setSystemStatus(SystemStatus.CANCEL.getName());
            rxMainRepository.save(rxMain);
        });
    }
}
